package com.test.service;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.test.mapper.PeopleListMapper;
import com.test.po.People;
import com.test.po.PeopleExample;
import com.test.po.PeopleList;
import com.test.po.PeopleListExample;
@Service
public class PeopleListServiceImpl implements PeopleListService{

	@Autowired
	private PeopleListMapper peopleListMapper;
	
	@Override
	//@Transactional(isolation = Isolation.REPEATABLE_READ)
	public PageInfo<PeopleList> getUPeople(int page, int pageSize) {
		// People users=peopleMapper.selectByPrimaryKey(1);
		PageHelper.startPage(page, pageSize);
		PeopleListExample example = new PeopleListExample();
		List<PeopleList> peoples = (List<PeopleList>) peopleListMapper.selectByExample(example);
		PageInfo<PeopleList> peopleList = new PageInfo<PeopleList>(peoples, pageSize);
		System.out.println(peopleList.getSize());
		
		 try {
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 pageSize++;
		PageHelper.startPage(page, pageSize);
		PeopleListExample example2 = new PeopleListExample();
		List<PeopleList> peoples2 = (List<PeopleList>) peopleListMapper.selectByExample(example2);
		PageInfo<PeopleList> peopleList2 = new PageInfo<PeopleList>(peoples2, pageSize);
		System.out.println(peopleList2.getSize());
		
		return peopleList;
	}

	@Override
	public PageInfo<PeopleList> getPeopleUnion(int page, int pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@Transactional  ( rollbackFor=Exception.class) 
	public	 int savePeopleList(PeopleList peopleList) throws IOException {
		peopleListMapper.insert(peopleList);

////		int j = 1/0;
//		 try {
//				Thread.sleep(10000);
//			} catch (InterruptedException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
		return 1;
	}

	@Override
//	@Transactional 
	public int savePeopleList2(PeopleList peopleList) throws IOException {		
		return savePeopleList(peopleList);
	}
	
	
//	@Override
//	@Transactional( rollbackFor=Exception.class)
//	public int savePeopleList(PeopleList peopleList) throws IOException {
//		peopleListMapper.insert(peopleList);
////		int j = 1/0;
//		  try {
//			Thread.sleep(10000);
//		} catch (InterruptedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		  int j = 1/0;
//		return 1;
//	}
}
